<template>
  <a-modal
    :title="data.id && '编辑类型'||'新增类型'"
    centered
    :visible="true"
    @cancel="dialogClosed"
  >

    <a-form
      :form="form"
    >
      <a-form-item label="类型名称" class="label-width-auto" v-bind="formItemLayout">
        <a-input
          v-decorator="[
            'name',
            { rules: [{ required: true, message: '请输入类型名称' }] },
          ]"
          placeholder="请输入"
        />
      </a-form-item>
    </a-form>
    <span slot="footer" class="dialog-footer">
      <a-button @click="dialogClosed()">取消</a-button>
      <a-button id="submit" :loading="submitButton.status" type="primary" @click="dataFormSubmit()">{{ submitButton.text }}</a-button>
    </span>
  </a-modal>
</template>

<script>
import { edit } from '@/pages/leave/api/leaveType'
import formItem from '@/config/formItemLayout'
export default {
  name: 'LeaveTypeSave',
  props: {
    data: {
      type: Object,
      default: function () {
        return {}
      }
    }
  },
  data () {
    return {
      form: this.$form.createForm(this),
      formItemLayout: formItem,
      submitButton: {
        text: '提交',
        status: false
      }
    }
  },
  mounted () {
    console.log(this.data)
    this.$initForm(this.form, this.data)
  },
  methods: {
    dialogClosed () {
      this.$emit('dialogClosed')
    },
    // 表单提交
    dataFormSubmit () {
      this.$saveQuit('form', edit(this.data.id), (data) => {
        data.id = this.data.id || null
        return data
      })
    }

  }
}
</script>
